# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=netavark
_commit=f6a0729c69997a2e36a0a62be1341f1107d6e8e8  # refs/tags/v1.6.0
pkgver=1.6.0
pkgrel=1
pkgdesc="Container network stack"
arch=(loong64 x86_64)
url="https://github.com/containers/netavark"
license=(Apache)
depends=(
  gcc-libs
  glibc
)
makedepends=(
  cargo
  git
  libgit2
  mandown
  protobuf
)
optdepends=('aardvark-dns: for authorative DNS server')
provides=(container-network-stack=2)
source=(git+https://github.com/containers/netavark.git#tag=$_commit)
sha256sums=('SKIP')
# NOTE: pinning commit until upstream clarifies commitment to chain of trust:
# https://github.com/containers/netavark/issues/231
# validpgpkeys=('74FE091D25519980B2D84447160386BECB6F0643')  # Brent Baude <bbaude@redhat.com>

prepare() {
  cd $pkgname
  cargo fetch --target "$CARCH-unknown-linux-gnu"
}

build() {
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target

  cd $pkgname
  # generate man page directly as docs target is broken: https://github.com/containers/netavark/issues/524
  mandown docs/$pkgname.1.md > $pkgname.1
  find -name Cargo.lock -exec rm -f {} \;
  mkdir -p .cargo
  cat > .cargo/config.toml <<EOF
[source.crates-io]
registry = "https://gitee.com/yetist/crates.io-index"
EOF
  cargo build --release --all-features
  make -C docs
}

check() {
  export RUSTUP_TOOLCHAIN=stable

  cd $pkgname
  cargo test --frozen --all-features
}

package() {
  cd $pkgname
  install -vDm 755 target/release/$pkgname -t "$pkgdir/usr/lib/podman/"
  install -vDm 644 $pkgname.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
